package com.jp.knowledge.activity;

import android.content.Intent;
import android.view.View;

import com.jp.knowledge.R;
import com.jp.knowledge.dialog.TeamCircleCreateCompanySelectDialog;

import java.io.Serializable;

/**
 * Created by 528787067@qq.com on 2017/3/21.
 */

public class TeamCirclePushToActivity extends TeamCircleSelectVisibilityActivity {

    private String companyId;
    private String companyName;
    private int companyType;

    private TeamCircleCreateCompanySelectDialog companySelectDialog;

    @Override
    protected void init() {
        super.init();

        companyId = intent.getStringExtra(TeamCircleCreateActivity.COMPANY_ID);
        companyName = intent.getStringExtra(TeamCircleCreateActivity.COMPANY_NAME);
        companyType = intent.getIntExtra(TeamCircleCreateActivity.COMPANY_TYPE, 1);

        topName.setText("发表到");
        rightBtn.setText("确定");
        visibilityAllLeftText.setText("当前组织");
        visibilityAllRightText.setText(companyName);
        visibilitySomeone.setVisibility(View.GONE);

        companySelectDialog = new TeamCircleCreateCompanySelectDialog(this);
        companySelectDialog.setCompanySelectedListener(new TeamCircleCreateCompanySelectDialog.CompanySelectedListener() {
            @Override
            public void onCompanySelected(String companyId, String companyName, int companyType) {
                TeamCirclePushToActivity.this.companyId = companyId;
                TeamCirclePushToActivity.this.companyName = companyName;
                TeamCirclePushToActivity.this.companyType = companyType;
                setTitleLeftIcon(1);
                visibilityAllRightText.setText(companyName);
            }
        });
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.team_circle_visibility_all){
            companySelectDialog.show(application.getUserData().getCompanyList());
        } else if(v.getId() == R.id.team_circle_visibility_others){
            Intent othersIntent = new Intent(this, TeamCirclePushToCompanyActivity.class);
            startActivityForResult(othersIntent, SET_VISIBILITY_COMPANY_CODE);
        } else if(v.getId() == R.id.right_bn){
            Intent finishIntent = getIntent();
            finishIntent.putExtra(VISIBILITY_TYPE, visibilityType);
            finishIntent.putExtra(TeamCircleCreateActivity.COMPANY_ID, companyId);
            finishIntent.putExtra(TeamCircleCreateActivity.COMPANY_NAME, companyName);
            finishIntent.putExtra(TeamCircleCreateActivity.COMPANY_TYPE, companyType);
            finishIntent.putExtra(TEAM_CIRCLE_CONSTACTS_MODEL_LIST, (Serializable) visibilityModelList);
            finishIntent.putExtra(TEAM_CIRCLE_COMPANY_MODEL_LIST, (Serializable) visibilityCompanyModeList);
            setResult(RESULT_OK, finishIntent);
            finish();
        } else {
            super.onClick(v);
        }
    }
}
